clc, clear, global a b c e g
a=[0.03,0.01,0.02,0.01];
b=[6,8,7,5]; 
c=[10000,10000,250,100];
e=[9,15]; g=[300,500];

p.options = optimoptions('fmincon','Algorithm','sqp');
p.solver = 'fmincon';
p.objective = @fun1
p.x0 = 10*rand(8,1);
p.nonlcon=@fun2;
p.lb=zeros(8,1);
[x,fval,flag]=fmincon(p)
x=reshape(x,[2,4])
y1=sum(x), y2=sum(x,2)  %计算原材料量和产量

function f=fun1(x);
global b e
x=reshape(x,[2,4]);
f=-(e*sum(x,2)-sum(x)*b');
end

function [f1,f2]=fun2(x);
global a b c g
x=reshape(x,[2,4]);
r=(a(1)*(x(1,1)+x(2,1))+a(2)*(x(1,2)+x(2,2))+a(4)*(x(1,4)+x(2,4)))/...
    (x(1,1)+x(2,1)+x(1,2)+x(2,2)+x(1,4)+x(2,4));
f1=[0.1*sum(x(1,:))-x(1,:)';0.1*sum(x(2,:))-x(2,:)'; sum(x)'-c' 
    (x(1,1)+x(1,2)+x(1,4))*r+a(3)*x(1,3)-0.025*sum(x(1,:))
    (x(2,1)+x(2,2)+x(2,4))*r+a(3)*x(2,3)-0.015*sum(x(2,:))
    sum(x,2)-g'];
f2=[x(1,1)*x(2,2)-x(1,2)*x(2,1)
    x(1,2)*x(2,4)-x(1,4)*x(2,2)];     %两个非线性等号约束
end